\hypertarget{pam__quiz_8c}{
\section{/Users/hitokiri/Documents/Code/pam\_\-quizc/pam\_\-quiz.c File Reference}
\label{pam__quiz_8c}\index{/Users/hitokiri/Documents/Code/pam\_\-quizc/pam\_\-quiz.c@{/Users/hitokiri/Documents/Code/pam\_\-quizc/pam\_\-quiz.c}}
}
{\tt \#include $<$stdlib.h$>$}\par
{\tt \#include $<$time.h$>$}\par
{\tt \#include $<$stdio.h$>$}\par
{\tt \#include $<$string.h$>$}\par
{\tt \#include $<$syslog.h$>$}\par
{\tt \#include $<$security/pam\_\-modules.h$>$}\par


Include dependency graph for pam\_\-quiz.c:\subsection*{Data Structures}
\begin{CompactItemize}
\item 
struct \hyperlink{struct_question}{Question}
\end{CompactItemize}
\subsection*{Defines}
\begin{CompactItemize}
\item 
\#define \hyperlink{pam__quiz_8c_0ebda8822b7fdfa5452de792b426603e}{PAM\_\-SM\_\-ACCOUNT}
\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
void \hyperlink{pam__quiz_8c_4ce5e253c38e2b50c4edb897005323df}{setMessage} (int type, const char $\ast$, struct pam\_\-message $\ast$)
\item 
int \hyperlink{pam__quiz_8c_b31fd37bc48e0612e53d306811083aad}{converse} (pam\_\-handle\_\-t $\ast$pamh, int args, struct pam\_\-message $\ast$$\ast$message, struct pam\_\-response $\ast$$\ast$repsonse)
\item 
void \hyperlink{pam__quiz_8c_2708657d5b0d8a461effdd163b0a2084}{makeMathQuestion} (struct \hyperlink{struct_question}{Question} $\ast$)
\item 
PAM\_\-EXTERN int \hyperlink{pam__quiz_8c_4fc07a18e4e61cc5b4d6ded1555d54c1}{pam\_\-sm\_\-acct\_\-mgmt} (pam\_\-handle\_\-t $\ast$pamh, int flags, int argc, const char $\ast$$\ast$argvc)
\end{CompactItemize}


\subsection{Define Documentation}
\hypertarget{pam__quiz_8c_0ebda8822b7fdfa5452de792b426603e}{
\index{pam\_\-quiz.c@{pam\_\-quiz.c}!PAM\_\-SM\_\-ACCOUNT@{PAM\_\-SM\_\-ACCOUNT}}
\index{PAM\_\-SM\_\-ACCOUNT@{PAM\_\-SM\_\-ACCOUNT}!pam_quiz.c@{pam\_\-quiz.c}}
\subsubsection[{PAM\_\-SM\_\-ACCOUNT}]{\setlength{\rightskip}{0pt plus 5cm}\#define PAM\_\-SM\_\-ACCOUNT}}
\label{pam__quiz_8c_0ebda8822b7fdfa5452de792b426603e}


This define tells the PAM system that this is an account module 

\subsection{Function Documentation}
\hypertarget{pam__quiz_8c_b31fd37bc48e0612e53d306811083aad}{
\index{pam\_\-quiz.c@{pam\_\-quiz.c}!converse@{converse}}
\index{converse@{converse}!pam_quiz.c@{pam\_\-quiz.c}}
\subsubsection[{converse}]{\setlength{\rightskip}{0pt plus 5cm}int converse (pam\_\-handle\_\-t $\ast$ {\em pamh}, \/  int {\em args}, \/  struct pam\_\-message $\ast$$\ast$ {\em message}, \/  struct pam\_\-response $\ast$$\ast$ {\em repsonse})}}
\label{pam__quiz_8c_b31fd37bc48e0612e53d306811083aad}


converse handles the pam\_\-converse() funciton. Essentially this function is a wrapper to handle all communication from the module to the calling application. It checks for errors and sets the appropriate response structure for you. This was all pretty much taken straight from pam\_\-stres.c

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em pamh}]This is the pointer to the pam environment. \item[{\em args}]This tells the converse function which message in teh message structure to use. Best just to use it as 1. \item[{\em response}]is the response from the conversation. \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]PAM\_\-SUCCESS if everything works well, or various PAM errors otherwise. \end{Desc}
\begin{Desc}
\item[See also:]$<$security/pam\_\-modules.h$>$ 

pam\_\-stress.c \end{Desc}
\hypertarget{pam__quiz_8c_2708657d5b0d8a461effdd163b0a2084}{
\index{pam\_\-quiz.c@{pam\_\-quiz.c}!makeMathQuestion@{makeMathQuestion}}
\index{makeMathQuestion@{makeMathQuestion}!pam_quiz.c@{pam\_\-quiz.c}}
\subsubsection[{makeMathQuestion}]{\setlength{\rightskip}{0pt plus 5cm}void makeMathQuestion (struct {\bf Question} $\ast$ {\em q})}}
\label{pam__quiz_8c_2708657d5b0d8a461effdd163b0a2084}


makeMathQuestion does the work of creating the mathQuestions to be asked. So The process is pretty straightforward. We generate some random numbers between 1 \& 10. These numbers correspond to the question x + y = ? The operand used is also a random number generated as well. As of writing this, the division Operand is not used. It is a pain. \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em q}]A question structure used to hold the question and answer this function generates. \end{description}
\end{Desc}
\hypertarget{pam__quiz_8c_4fc07a18e4e61cc5b4d6ded1555d54c1}{
\index{pam\_\-quiz.c@{pam\_\-quiz.c}!pam\_\-sm\_\-acct\_\-mgmt@{pam\_\-sm\_\-acct\_\-mgmt}}
\index{pam\_\-sm\_\-acct\_\-mgmt@{pam\_\-sm\_\-acct\_\-mgmt}!pam_quiz.c@{pam\_\-quiz.c}}
\subsubsection[{pam\_\-sm\_\-acct\_\-mgmt}]{\setlength{\rightskip}{0pt plus 5cm}PAM\_\-EXTERN int pam\_\-sm\_\-acct\_\-mgmt (pam\_\-handle\_\-t $\ast$ {\em pamh}, \/  int {\em flags}, \/  int {\em argc}, \/  const char $\ast$$\ast$ {\em argvc})}}
\label{pam__quiz_8c_4fc07a18e4e61cc5b4d6ded1555d54c1}


pam\_\-sm\_\-acct\_\-mgmt is the method PAM will use to do account authorization. The purpose of this method is to simply ask questions to the user randomly and assess if they are human or not. What this boils down to is if they can get x out of y questions correct, they will be authorized.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em pamh}]This is the pam environment. The pam system sets this. \item[{\em flags}]I don't have any use for these. \item[{\em argc}]How many argments have been passed from various pam conf files. \item[{\em argvc}]The argments array itself. \end{description}
\end{Desc}


Order of Events: -1) Get a conversation function pointer to the application (Hopefully). -2) Generate question based on random numbers and flags (Future). -3) Build the conversation functions' message structure and response structure. -Note: Send only one message at a time. (Compatability) -4) Initiate the conversation. -5) Check the response structure for the correct answer. -6) Repeat if necessary (Future). -7) Free the response strucutre -8) Return our success or failure. \hypertarget{pam__quiz_8c_4ce5e253c38e2b50c4edb897005323df}{
\index{pam\_\-quiz.c@{pam\_\-quiz.c}!setMessage@{setMessage}}
\index{setMessage@{setMessage}!pam_quiz.c@{pam\_\-quiz.c}}
\subsubsection[{setMessage}]{\setlength{\rightskip}{0pt plus 5cm}void setMessage (int {\em type}, \/  const char $\ast$ {\em msg}, \/  struct pam\_\-message $\ast$ {\em message})}}
\label{pam__quiz_8c_4ce5e253c38e2b50c4edb897005323df}


\hyperlink{pam__quiz_8c}{Pam\_\-quiz.c} is a PAM module that serves a simple purpose. It is an account management module requries that users respond to simple (math) questions before being allowed to proceed. There are variables to adjust how many questions to ask as well as a percentage needed to be correct.

If one answers too few questions correctly, they will not be authorized, and if they do, they will be authorized. setMessage is a simple function that does the job to filling up the pam\_\-message structure for me. It exists just out of convenience. \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em type}]This is a define from the pam headers for the conversation functions to use. \item[{\em msg}]This is the string that you want sent to the user. \item[{\em message}]This is the struct pam\_\-message that is used to converse with.\end{description}
\end{Desc}
setMessage simply does the job of setting up the message structure. Just here for convenience. 